package edu.zjut.hjg.saas.web.controller.home;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import edu.zjut.hjg.saas.biz.service.ActivityService;
import edu.zjut.hjg.saas.biz.service.LocationService;
import edu.zjut.hjg.saas.biz.service.UserLogService;

/**
 * 首页
 * 
 * @author hjg
 */
@Controller
@RequestMapping("/")
public class IndexController {

    @Value("${saas.web.app.server.port}")
    private int             appServerPort;

    @Autowired
    private UserLogService  userLogService;

    @Autowired
    private LocationService locationService;

    @Autowired
    private ActivityService activityService;

    @RequestMapping("index.htm")
    public String index(Model model) {
        model.addAttribute("userLogs", userLogService.listFreshByLimit(6));
        model.addAttribute("port", (appServerPort == 80 ? "" : ":" + appServerPort));
        model.addAttribute("provinces", locationService.listAllProvinces());
        model.addAttribute("activities", activityService.listByLimit(5));
        return "index";
    }
}
